using System;
using System.Collections.Generic;
using System.Linq;
using System.Data;
using System.Runtime.Serialization;

namespace lt_pmbc_001.DAL
{
	#region using
	using System.Data;
	using lt_pmbc_001.DTO;
	using lt_pmbc_001.Helpers;
    using System.Data.OleDb;
	#endregion

	/// <summary>
	/// Data access object, which get data of DiaDiem table from database
	/// </summary>
    public class DiaDiemDAL : AbstractDAL
	{
		public DiaDiemDAL(string strPath): base(strPath)
		{
		}

		public DataSet SelectAll()
		{
			DataSet ds;
			try
			{
				ds = new DataSet();
				base.sql = "usp_DiaDiem_SelectAll";
				base.FillDataSet(ref ds, "DiaDiem");
				return ds;
			}
			catch(System.Exception ex)
			{
				if (ex.InnerException != null)
				{
					GlobalVariables.Logger.Error(ex.InnerException.Message);
				}
				else
				{
					GlobalVariables.Logger.Error(ex.Message);
				}
			}
			finally
			{
				base.CleanUpObject();
			}
			return null;
		}

		public DataSet SelectByID(int id)
		{
			DataSet ds;
			try
			{
				ds = new DataSet();
				base.sql = "usp_DiaDiem_SelectByID";
				base.InitializeCommand();
				base.AddParameter("@ID", OleDbType.Integer, 1000, id);
				base.FillDataSet(ref ds, "DiaDiem");
				return ds;
			}
			catch(System.Exception ex)
			{
				if (ex.InnerException != null)
				{
					GlobalVariables.Logger.Error(ex.InnerException.Message);
				}
				else
				{
					GlobalVariables.Logger.Error(ex.Message);
				}
			}
			finally
			{
				base.CleanUpObject();
			}
			return null;
		}

		public bool Insert(DiaDiemDTO obj)
		{
			try
			{
				base.sql = "usp_DiaDiem_Insert";
				base.InitializeCommand();
                base.AddParameter("@DiaDiem", OleDbType.VarChar, 1000, obj.DiaDiem);
                base.AddParameter("@DiaChi", OleDbType.VarChar, 1000, obj.DiaChi);
				return ExecuteStoredProcedure();
			}
			catch(Exception ex)
			{
                if (ex.InnerException != null)
                {
                    GlobalVariables.Logger.Error(ex.InnerException.Message);
                }
                else
                {
                    GlobalVariables.Logger.Error(ex.Message);
                }
				return false;
			}
		}

		public bool Update(DiaDiemDTO obj)
		{
			try
			{
				base.sql = "usp_DiaDiem_Update";
				base.InitializeCommand();
				base.AddParameter("@DiaDiem", OleDbType.VarChar, 1000, obj.DiaDiem);
                base.AddParameter("@DiaChi", OleDbType.VarChar, 1000, obj.DiaChi);
                base.AddParameter("@ID", OleDbType.Integer, 1000, obj.ID);
				return ExecuteStoredProcedure();
			}
			catch(Exception ex)
			{
                if (ex.InnerException != null)
                {
                    GlobalVariables.Logger.Error(ex.InnerException.Message);
                }
                else
                {
                    GlobalVariables.Logger.Error(ex.Message);
                }
				return false;
			}
		}

		public bool Delete(int id)
		{
			try
			{
				base.sql = "usp_DiaDiem_Delete";
				base.InitializeCommand();
				base.AddParameter("@ID", OleDbType.Integer, 1000, id);
				return ExecuteStoredProcedure();
			}
			catch(Exception ex)
			{
                if (ex.InnerException != null)
                {
                    GlobalVariables.Logger.Error(ex.InnerException.Message);
                }
                else
                {
                    GlobalVariables.Logger.Error(ex.Message);
                }
				return false;
			}
		}

	}
}